import store from '@/store'
import toastr from '@/assets/utils/toastr'
import storage from '@/assets/utils/Storage'

import CacheMethod from '@/assets/utils/CacheMethod'

console.log(CacheMethod)

const Toastr = toastr.toastr
const Storage = storage.storage

const config = {
	baesUrl:'https://uat.mumway.com/',
	data(data){
		return data
	},
	success(res, callback){
		let response = res.data;
		if (typeof response == 'string') {
			response = JSON.parse(res.data)
		}
		callback(response)
	},
	error(error){
		// console.log(error)
	},
	complete(data){
		Toastr.hideLoading()

	}
}



const Axios = {
	uploadFile(url, filePath, name, formData, callback){
		Toastr.clearTimeout()
		Toastr.showLoading('上传中')

		mpvue.uploadFile({
			url:config.baesUrl + url,
			filePath: filePath,
			formData: formData,
			name: name,
			success(res){
				config.success(res, callback)

			},
			fail:config.error,
			complete:config.complete
		})
	},
	post(url, data, callback){
		console.log(config.data(data))
		mpvue.request({
			url: config.baesUrl + url,
			data: config.data(data),
			method:'POST',
			success(res){
				config.success(res, callback)
			},
			fail:config.error,
			complete:config.complete
		})
	},
	get(url, data, callback){
		mpvue.request({
			url: config.baesUrl + url,
			data: config.data(data),
			method:'GET',
			success(res){
				config.success(res, callback)
			},
			fail:config.error,
			complete:config.complete
		})
		
	}
}


export default {
	install: function(Vue, Option) {
		Object.defineProperty(Vue.prototype, "$http", { value: Axios });
	},
	Axios:Axios
};